<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>finalBlog 后台管理登陆</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta content="" name="description"/>
<meta content="" name="author"/>
<link rel="shortcut icon" href="${basePath}/favicon.ico" type=”image/x-icon”>
<link href="${basePath}/admin_res/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<link href="${basePath}/admin_res/css/simple-line-icons.min.css" rel="stylesheet" type="text/css"/>
<link href="${basePath}/admin_res/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="${basePath}/admin_res/css/uniform.default.css" rel="stylesheet" type="text/css"/>
<link href="${basePath}/admin_res/css/login3.css" rel="stylesheet" type="text/css"/>
<link href="${basePath}/admin_res/css/components.css" rel="stylesheet" type="text/css"/>
</head>
<body class="login">
<div class="logo">
	<a href="index.html">
	<img src="${basePath}/admin_res/img/bloglogo.png" alt=""/>
	</a>
</div>
<div class="content">	
	<form class="login-form" action="${basePath}/admin/login/validate"
		method="post" >
			<h3 class="form-title">登陆</h3>
			<div class="alert alert-danger display-hide">
				 <a href="#" class="close"></a>
				<span id="errormsg"></span>
			</div>
			<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9 ">用户名</label>
			<div class="input-icon">
				<i class="fa fa-user"></i> <input
					class="form-control placeholder-no-fix" type="text" validate="{required:true}" 
					value="${username!}"  placeholder="用户名"
					name="username" />
			</div>
		</div>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9 ">密码</label>
			<div class="input-icon">
				<i class="fa fa-lock"></i> <input
					class="form-control placeholder-no-fix" type="password" validate="{required:true}"
					 placeholder="密码" name="password" />
			</div>
		</div>
		<div class="form-group">
			<label class="control-label visible-ie8 visible-ie9" >验证码</label>
			<div class="input-icon">
				<i class="fa fa-lock"></i> <input
					class="form-control placeholder-no-fix randcode" type="text" validate="{required:true}"
					autocomplete="off" placeholder="验证码" name="captcha" /> <img
					title="换一张试试" name="randImage" id="randImage" height="33px"
					class="yzm-img" />
			</div>
		</div>
		<div class="form-actions">
			<label class="checkbox"> <input type="checkbox"
				name="remember" value="1" /> 记住我
			</label>
			<button type="submit" class="btn green-haze pull-right" id="submit-button">
				登陆 <i class="m-icon-swapright m-icon-white"></i>
			</button>
		</div>
	</form>
</div>
<!-- BEGIN COPYRIGHT -->
<div class="copyright">
	 2016 &copy; final blog
</div>
<script src="${basePath}/admin_res/js/jquery.min.js" type="text/javascript"></script>
<script src="${basePath}/admin_res/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${basePath}/admin_res/js/jquery.uniform.min.js" type="text/javascript"></script>
<script src="${basePath}/admin_res/js/jquery.validate.min.js" type="text/javascript"></script>
<script src="${basePath}/admin_res/js/MD5.js"type="text/javascript" ></script>
<script>
$(function(){
	$('.close', $('.login-form')).unbind('click').on('click',function(e){
		$('.alert-danger', $('.login-form')).hide();
	}) 
	$('#randImage').click(function(){
	     loadimage();
	});
	loadimage();
	$("input[name='remember']").uniform();
	$('.login-form').validate({
            errorElement: 'span', //default input error message container
            errorClass: 'help-block', // default input error message class
            focusInvalid: false, // do not focus the last invalid input
            highlight: function(element) { // hightlight error inputs
                $(element)
                    .closest('.form-group').addClass('has-error'); // set error class to the control group
            },
            success: function(label) {
                label.closest('.form-group').removeClass('has-error');
                label.remove();
            },
            errorPlacement: function(error, element) {
                error.insertAfter(element.closest('.input-icon'));
            },
            submitHandler: function(form) {
            	dosumbit(); // form validation success, call ajax form submit
            }
        });
        $('.login-form input').keypress(function(e) {
            if (e.which == 13) {
                if ($('.login-form').validate().form()) {
                	dosumbit();
                }
                return false;
            }
        });
})
function loadimage(){
	var url = '${basePath!}/admin/login/captcha?v='+Math.random();
	$('#randImage').attr('src',url);	
		
}
function dosumbit(){
	$('.alert-danger', $('.login-form')).hide();
	var str1 = hex_md5($("input[name='password']").val());
	$("input[name='password']").val(str1);
	var data = $('.login-form').serialize();
	var url = $('.login-form').attr('action');
	$.post(url,data,function(result){
		if(result.success==true){
			var url = "${basePath}"+result.toUrl;
			console.log(url);
			window.location.href=url;
		}else{
			$("#errormsg").text(result.msg);
			loadimage();
			$('.alert-danger', $('.login-form')).show();
		}
	});
}
</script>
</body>
</html>